package practice;

import java.util.*;
import java.util.stream.Collectors;

/**
 * 找出数组中的众数 作为新的数组 输出其中位数
 */
public class MedianAndCenter {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int[] arr = Arrays.stream(sc.nextLine().split(" "))
                    .mapToInt(Integer::parseInt)
                    .toArray();
            Map<Integer, Integer> countMap = new HashMap<>(arr.length);
            for (int i: arr) {
                countMap.put(i,countMap.getOrDefault(i,0) + 1);
            }
            Map.Entry<Integer, Integer> maxEntry = countMap.entrySet()
                    .stream().min((o1, o2) -> o2.getValue() - o1.getValue())
                    .orElseThrow(() -> new RuntimeException("输入有误"));
            // 出现最多的次数
            Integer maxFrequence = maxEntry.getValue();
            Map<Integer, Integer> centerMap = countMap.entrySet()
                    .stream().filter(entry -> entry.getValue().equals(maxFrequence))
                    .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
            List<Integer> list = new ArrayList<>();
            for (Map.Entry<Integer,Integer> entry: centerMap.entrySet()) {
                Integer count = entry.getValue();
                while (count > 0) {
                    list.add(entry.getKey());
                    count--;
                }
            }
            Collections.sort(list);

            if (list.size() % 2 == 0) {
                int i1 = list.size() /2;
                int i2 = i1-1;
                System.out.println((list.get(i1) + list.get(i2)) / 2);
            } else {
                System.out.println(list.get(list.size()/2));
            }
        }
    }
}
